using System;
using System.Linq;
using Sirenix.OdinInspector;
using Sirenix.Serialization;
using UnityEngine;

namespace cmd
{
    [AssetList]
    public sealed class FishTypeDataSO : SerializedScriptableObject
    {
        [field: OdinSerialize]
        public FishTypeData FishTypeData { get; private set; } = new();

        [Button(ButtonSizes.Medium), PropertySpace(10)]
        private void SetFishTypeNameAndId()
        {
            // 提取name开头的数字作为Id
            FishTypeData.Name = name.TrimStart('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
            if (uint.TryParse(name[..^FishTypeData.Name.Length], out uint id))
            {
                FishTypeData.Id = id;
            }

            PickableItemDataManager.CheckDuplicateFishTypeIds(false);
        }

        // void Awake()
        // {
        //     // SetFishTypeName();
        //     // FishTypeData.Id = ++PickableItemDataManager.MaxFishTypeDataId;
        //     // Debug.Log(
        //     //     $"初始name {name}\n 修剪后的name {name.TrimStart('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')}"
        //     // );
        // }
    }

    /// <summary>
    /// 鱼种类属性数据类
    /// </summary>
    [Serializable]
    public class FishTypeData
    {
        [field: SerializeField]
        [field: LabelText("种类ID")]
        public uint Id { get; protected internal set; }

        [field: SerializeField, Space(10)]
        [field: LabelText("品质")]
        // [field: InlineProperty]
        public IntRange Quality { get; protected set; } = IntRange.CreateWithLimitation(1, 3);

        [field: SerializeField, Space(10)]
        [field: LabelText("种类名称")]
        public string Name { get; protected internal set; }

        [field: SerializeField, Space(10)]
        [field: LabelText("基础重量")]
        public FloatRange BaseWeight { get; protected set; } =
            FloatRange.CreateWithLimitation(0, 100);

        [field: SerializeField]
        [field: LabelText("体积区间")]
        // [Tooltip("体积对应数值反应的实际显示大小(百分比)")]
        public FloatRange VolumeRange { get; protected set; } =
            FloatRange.CreateWithLimitation(50, 150);

        [field: SerializeField]
        [field: LabelText("移动速度")]
        // [Tooltip("体积是否影响速度？")]
        public FloatRange MoveSpeed { get; protected set; } =
            FloatRange.CreateWithLimitation(0, 10);

        [field: SerializeField]
        [field: LabelText("生成区间(百分比)")]
        [Tooltip("Y轴生成高度，0-1之间的百分比")]
        public FloatRange SpawnRangePercent { get; protected set; } =
            FloatRange.CreateWithLimitation(0, 100);

        [field: SerializeField]
        [field: LabelText("单位价值")]
        public FloatRange UnitValue { get; protected set; } =
            FloatRange.CreateWithLimitation(0, 100);
    }
}
